package com.guanzhi.mp.controller;

import com.baomidou.mybatisplus.extension.toolkit.Db;
import com.guanzhi.mp.api.AjaxResult;
import com.guanzhi.mp.po.BookPo;
import com.guanzhi.mp.service.BookIService;
import com.guanzhi.mp.service.BookService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Mybatis-Plus 练习
 * <p> Package: com.guanzhi.mp.controller </p>
 * <p> File: BookController.java </p>
 * <p> Description:  (图书 RestFul API)</p>
 * <p> Date: 2024/6/15 21:45</p>
 *
 * @author 观之
 * @version 1.0 （代码版本）
 * @email <a href="mailto:guanzhi55634@aliyun.com">观之</a>（邮箱）
 * @date 2024/6/15 21:45
 * @since jdk17（jdk版本）
 */
@RestController
@RequestMapping("/book")
@RequiredArgsConstructor
public class BookController {

    private final BookService bookService;

    private final BookIService bookIService;

    @GetMapping("/queryWrapper")
    public AjaxResult queryWrapper() {
        return AjaxResult.success(bookService.queryWrapper());
    }

    @GetMapping("/updateWrapper")
    public AjaxResult updateWrapper() {
        bookService.updateWrapper();
        return AjaxResult.success();
    }

    @GetMapping("/lambdaQueryWrapper")
    public AjaxResult lambdaQueryWrapper() {
        return AjaxResult.success(bookService.lambdaQueryWrapper());
    }

    @GetMapping("/customQuery")
    public AjaxResult customQuery() {
        return AjaxResult.success(bookService.customQuery());
    }

    @GetMapping("/addBookByIService")
    public AjaxResult addBookByIService() {
        BookPo bookPo = new BookPo();
        bookPo.setName("Java");
        bookPo.setAuthor("Guanzhi");
        bookIService.save(bookPo);
        return AjaxResult.success();
    }

    @GetMapping("/getIdByIService")
    public AjaxResult getIdByIService() {
        return AjaxResult.success(bookIService.getById(1152081921));
    }

    @GetMapping("/getIdByDb")
    public AjaxResult getIdByDb() {
        BookPo byId = Db.getById(1, BookPo.class);
        return AjaxResult.success(byId);
    }
}
